import { Component } from 'react'
import './wode.scss'
import http from '../../utils/http'
import Taro from '@tarojs/taro'
import React, { useEffect, useState } from 'react'
import { View, Text, Image, Navigator } from '@tarojs/components'
import { AtIcon, AtButton, AtModal, AtToast, AtAvatar } from 'taro-ui'
// import { fail } from 'assert'

const Wode = () => {
  // 头像
  const [tempFilePaths, setTempFilePaths] = useState()
  // 模态框
  const [isOpened, setisOpened] = useState(false)
  const [Opened, setOpened] = useState(false)
  const [text, settext] = useState('text')
  const [icon, setiscon] = useState('text')
  // 数据
  const [list, setList] = useState([])
  // 请求数据
  useEffect(() => {
    // 取出token
    let Gettoken = Taro.getStorageSync('token')
    http({
      url: '/user/userInformationQuery',
      method: 'post',
      data: {

      },
      header: {
        'token': Gettoken
      }
    }).then((res) => {
      console.log(res);
      // console.log(res.data.data[5].userName);
      Taro.setStorageSync('communityName', res.data.data[5].communityName)
    })

    let TempFilePaths = Taro.getStorageSync('tempFilePaths')
    setTempFilePaths(TempFilePaths)
    http({
      url: '/user/userInformationQuery',
      method: 'post',
      data: {

      },
      header: {
        'token': Gettoken
      }
    }).then((res) => {
      console.log(res);
      setList([res.data.data[1]])
      // if (res.data.code == 200) {
      //   Taro.setStorageSync('InformationQuery', res.data.data)
      // }
    })
  }, [])

  useEffect(() => {
    console.log(list);
  }, [list])

  const tiao = () => {
    // Taro.navigateToMiniProgram({
    //   // appId: 'wx43078d4baa3c29f1',
    //   appId: 'wx5aba82dfef589d4e',
    //   path: "/pages/Login/index",
    //   extraData: {
    //     phone: "13688466093",
    //     useImg: "用户头像"
    //   },
    //   envVersion: 'develop',
    //   success(res) {
    //     // 打开成功
    //     console.log(res);
    //   },
    //   fail(err) {
    //     console.log(err);
    //   }
    // })
  }


  // 上传头像
  const portrait = () => {
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        // console.log(res);
        // tempFilePath可以作为img标签的src属性显示图片
        const tempFilePaths = res.tempFilePaths[0]
        setTempFilePaths(tempFilePaths)
        Taro.setStorageSync('tempFilePaths', tempFilePaths)
      }
    })
  }

  // 退出登录

  const handleClose = (v) => {
    setisOpened(!isOpened)
  }
  const handleCancel = () => {
    setisOpened(!isOpened)
    setOpened(!Opened)
    setiscon('at-icon at-icon-close-circle')
    settext('已取消登录')
  }
  const handleConfirm = () => {
    setisOpened(!isOpened)
    setOpened(!Opened)
    setiscon('at-icon at-icon-check-circle')
    settext('成功退出登录')
    Taro.navigateTo({
      url: '../../pages/login/login',
    })
    Taro.removeStorageSync('token')
  }

  return <View className='cont'>


    {
      list.map((v, i) => {
        return <View>
          <View className='next' key={i}>
            <View className='ent'>
              <Text>{v.userName}</Text>
              <Text>拼团次数：{v.alreadyPick + v.notPick}</Text></View>
            <View className='image'>
              <Image onClick={portrait} src={tempFilePaths} />
            </View>
          </View>
          {/* 内容 */}
          <View className='content'>
            <Navigator url='./Nomention/Nomention'>
              <View>
                <Text>{v.notPick}</Text>
                <Text> 未提货</Text>
              </View>
            </Navigator>
            <Navigator url='./Mention/Mention'>
              <View>
                <Text>{v.alreadyPick}</Text>
                <Text>已提货</Text>
              </View>
            </Navigator>
          </View>
        </View>
      })
    }





    <View className='footer'>
      {/* 跳转到商家端 */}
      {/* <Navigator url='http://172.16.114.78/Login/index'> */}
      <View onClick={tiao}>
        <Text>申请入驻</Text>
      </View>
      {/* </Navigator> */}
      <Navigator url='./Advice/Advice'>
        <View>
          <Text>反馈建议</Text>
        </View>
      </Navigator>
    </View>
    {/* <View className='last'>
      <Text>社区拼团 - 团到超值</Text>
      <Text>1.0</Text>
    </View> */}
    <View className="last" >
      <AtButton className='last_last'
        onClick={() => { setisOpened(true); setOpened(false) }}
      >退出登录</AtButton>
    </View>
    {/* 模态框 */}
    <AtModal
      isOpened={isOpened}
      cancelText='取消'
      confirmText='确认'
      onClose={handleClose.bind(this)}
      onCancel={handleCancel.bind(this)}
      onConfirm={handleConfirm.bind(this)}
      content='确定要退出登录吗？'
    />
    {/* 提示框 */}
    <AtToast
      isOpened={Opened}
      text={text}
      icon={icon}
    ></AtToast>
  </View>

}
export default Wode